package com.ruoyi.system.service.carte.trans.impl;

import com.ruoyi.system.domain.XxkCarte;
import com.ruoyi.system.domain.request.BaseTransRequest;
import com.ruoyi.system.domain.request.TransStatusRequest;
import com.ruoyi.system.service.carte.AbstractCarteService;
import com.ruoyi.system.service.carte.CarteConst;
import com.ruoyi.system.service.carte.trans.ITransStatus;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.net.URLEncoder;

@Slf4j
@Service
public class TransStatusImpl extends AbstractCarteService implements ITransStatus {
    @Override
    public String transStatus(TransStatusRequest transRequest) {
        try{
            return commonHandle(transRequest);
        }catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return "error";
    }

    public  void setRequestUrl(XxkCarte xxkCarte, BaseTransRequest baseTransRequest ) throws Exception {
       TransStatusRequest transRequest =(TransStatusRequest)baseTransRequest;
        if(StringUtils.isBlank(transRequest.getXml())){
            transRequest.setXml("Y");
        }
        String url = "http://" + xxkCarte.getCarteIp() + ":" + xxkCarte.getCartePort()+ CarteConst.TRANS_STATUS_SUFFIXPATH
                + "?&name=" + URLEncoder.encode( transRequest.getName(), "UTF-8" ) + "&xml=" + transRequest.getXml();
        url = url.replace( " ", "%20" );
        transRequest.setRequestUrl(url);
    }
}
